import {esri} from "../api/esriAPI";

export class ManageGeometry {
  _layerManage = null;

  constructor(layerManage) {
    this._layerManage = layerManage;
  }

  //TODO 颜色等外露接口
  drawPointBySimple(key, x, y) {
    var point = {type: "point", x, y,};
    var markerSymbol = {
      type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
      color: [226, 119, 40],
      outline: {
        // autocasts as new SimpleLineSymbol()
        color: [255, 255, 255],
        width: 2
      }
    };
    var pointGraphic = new esri.Graphic({
      geometry: point,
      symbol: markerSymbol
    });
    this._layerManage.applyGraphicsLayer(key, {graphics: [pointGraphic]})
  }

  drawPolylineBySimple(key, paths) {
    var polyline = {
      type: "polyline",
      paths
    };
    // Create a symbol for drawing the line
    var lineSymbol = {
      type: "simple-line", // autocasts as SimpleLineSymbol()
      color: [226, 119, 40],
      width: 4
    };
    var polylineGraphic = new esri.Graphic({
      geometry: polyline,
      symbol: lineSymbol
    });
    this._layerManage.applyGraphicsLayer( key, {graphics: [polylineGraphic]})
  }

  drawPolygonBySimple(key, rings) {
    var polygon = {
      type: "polygon", // autocasts as new Polygon()
      rings
    };
    // Create a symbol for rendering the graphic
    var fillSymbol = {
      type: "simple-fill", // autocasts as new SimpleFillSymbol()
      color: [227, 139, 79, 0.8],
      outline: {
        // autocasts as new SimpleLineSymbol()
        color: [255, 255, 255],
        width: 1
      }
    };
    // Add the geometry and symbol to a new graphic
    var polygonGraphic = new esri.Graphic({
      geometry: polygon,
      symbol: fillSymbol
    });
    this._layerManage.applyGraphicsLayer( key, {graphics: [polygonGraphic]})
  }
}
